package com.example.oj_system.common;

import lombok.Data;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86187
 * Date: 2023-05-23
 * Time: 12:43
 */
@Data
public class ResultAnswer {
    // 状态码
    private Integer code;
    // 状态码描述信息
    private String msg;
    // 返回的数据信息
    private Object body;

    /**
     *  操作成功返回的结果.
     */
    public static ResultAnswer success(Object data) {
        ResultAnswer result = new ResultAnswer();
        result.setCode(200);
        result.setMsg("");
        result.setBody(data);
        return result;
    }
    public static ResultAnswer success(int code, Object data) {
        ResultAnswer result = new ResultAnswer();
        result.setCode(code);
        result.setMsg("");
        result.setBody(data);
        return result;
    }
    public static ResultAnswer success(int code, String msg, Object data) {
        ResultAnswer result = new ResultAnswer();
        result.setCode(code);
        result.setMsg(msg);
        result.setBody(data);
        return result;
    }


    /**
     *  返回失败的结果.
     */
    public static ResultAnswer fail(int code, String msg) {
        ResultAnswer result = new ResultAnswer();
        result.setCode(code);
        result.setMsg(msg);
        result.setBody(null);
        return result;
    }
    public static ResultAnswer fail(int code, String msg, Object data) {
        ResultAnswer result = new ResultAnswer();
        result.setCode(code);
        result.setMsg(msg);
        result.setBody(data);
        return result;
    }
}
